import { SelectAvatarProps } from "@/types/props";
import { View } from "@tarojs/components";
import { Image } from "@taroify/core";
import { chooseImg } from "@/utils";
import { useState } from "react";

export default ({ size = 100, change }: SelectAvatarProps) => {
  const [avatar, setAvatar] = useState("https://img.yzcdn.cn/vant/cat.jpeg");
  async function selectAvatar() {
    const img = await chooseImg();
    setAvatar(img);
    change && change(img);
  }
  return (
    <View>
      <Image
        onClick={selectAvatar}
        className=" rounded-full"
        mode="scaleToFill"
        width={size}
        height={size}
        src={avatar}
      />
    </View>
  );
};
